package com.flag.app;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.deserializer.JavaObjectDeserializer;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;

public class TypeTest {

 
    

    
    public static ObjectDeserializer getDeserializer(Type type) {

        if (type instanceof Class<?>) {
           System.err.println("type instanceof Class<?>: " + type);
        }

        if (type instanceof ParameterizedType) {
        	System.err.println("type instanceof ParameterizedType: " + type);
            Type rawType = ((ParameterizedType) type).getRawType();
            Type actualTypeType = ((ParameterizedType) type).getActualTypeArguments()[0];
            if (rawType instanceof Class<?>) {
            	 System.err.println("rawType instanceof Class<?>: " + rawType);
            	 System.err.println("actualTypeType: " + actualTypeType);
            } else {
                return getDeserializer(rawType);
            }
        }

        return JavaObjectDeserializer.instance;
    }
    
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		TypeReference<List<String>> typeReference = new TypeReference<List<String>>(){};
		System.err.println(typeReference.getType());
		getDeserializer(typeReference.getType());
		
		List<String> strings = new ArrayList<String>();;
		System.err.println(strings.getClass().getComponentType());
	}

}
